var e = require("../../requests/request.js");

Page({
    data: {
        winWidth: 0,
        winHeight: 0,
        catid: 1,
        pageindex: 1,
        pagesize: 20,
        videomore: [],
        searchLoading: !1,
        searchLoadingComplete: !1
    },
    onLoad: function(e) {
        console.log(e), this.setData({
            catid: e.catid
        }), wx.setNavigationBarTitle({
            title: decodeURIComponent(e.catname)
        }), this.getVideoList(e.catid);
    },
    getVideoList: function(t) {
        console.log("pageindex=" + this.data.pageindex);
        var a = this;
        e.getVideolist(t, a.data.pageindex, a.data.pagesize, function(e) {
            if (console.log(e), e.Data.rowCount > 0) if (console.log(e.Data.Table.length), e.Data.Table.length > 0) {
                var t = e.Data.Table;
                if (t) {
                    for (var o = 0; o < t.length; o++) t[o].TotalVisit = t[o].TotalVisit > 1e4 ? (t[o].TotalVisit / 1e4).toFixed(1) + "万" : t[o].TotalVisit;
                    a.setData({
                        videomore: a.data.videomore.concat(t),
                        searchLoading: !0
                    });
                }
                a.setData({
                    searchLoading: !0
                });
            } else a.setData({
                searchLoadingComplete: !0,
                searchLoading: !1
            });
        }, function() {
            console.log("getVideocat more list complete.");
        }, function() {
            console.log("getVideocat more list complete.");
        });
    },
    onPullDownRefresh: function() {
        var e = this;
        console.log("onPullDownRefresh catid=" + e.data.catid), wx.showNavigationBarLoading(), 
        e.setData({
            pageindex: 1,
            videomore: []
        }), e.getVideoList(e.data.catid), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
    },
    onReachBottom: function() {
        var e = this;
        if (console.log("onReachBottom catid=" + e.data.catid), e.data.searchLoading && !e.data.searchLoadingComplete) {
            var t = e.data.pageindex + 1;
            e.setData({
                pageindex: t
            }), e.getVideoList(e.data.catid);
        }
        wx.stopPullDownRefresh();
    },
    toVideoDetail: function(e) {
        var t = this, a = e.currentTarget.dataset.id, o = e.currentTarget.dataset.index - 1;
        console.log("toVideoDetail videoid=" + a + " index=" + o);
        var i = t.data.videomore[o], n = "id=" + i.VideoId + "&Author=" + i.Author + "&PublishTime=" + i.PublishTime;
        n += "&TotalVisit=" + i.TotalVisit + "&CategoryName=" + i.CategoryName + "&Duration=" + i.Duration + "&Title=" + i.Title + "&Mp4Link=" + i.Mp4Link + "&imgelink=" + i.ImageLink, 
        wx.navigateTo({
            url: "../video/video?" + n
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    pullUpLoad: function() {
        console.log("pullUpLoad catid=" + this.data.catid);
    },
    onShareAppMessage: function() {
        return {
            title: "专业的汽车资讯"
        };
    }
});